#pragma once

#include<BWAPI.h>

#include"Location.h"

using namespace BWAPI;

namespace Custom
{
	class Unit;
}

class Command
{
public:
	enum Type{Undefined , Attack , Move , Skip};
	Command()
		:Type(Undefined),
		TargetUnit(NULL),
		TargetPosition(0 , 0)
	{
	}
	Command(Type type)//Attack
		:Type(type),
		TargetUnit(NULL),
		TargetPosition(0 , 0)
	{
	}
	Command(Type type , Location location)//Move
		:Type(type),
		TargetUnit(NULL),
		TargetPosition(location)
	{
	}
	Command(Custom::Unit* target)
		:Type(Undefined),
		TargetUnit(target),
		TargetPosition(0 , 0)
	{
	}
	//--
	Type Type;
	Custom::Unit* TargetUnit;
	Location TargetPosition;
};


class ControlCommand
{
public:
	enum Type{Attack , Move};
	ControlCommand()
		:Type(Attack),
		Target(NULL),
		TargetPosition(0 , 0)
	{
	}
	//--
	Type Type;
	Unit* Target;
	Location TargetPosition;
};

void SmartAttackUnit(Unit * attacker , Unit * target)
{

	// if we have issued a command to this unit already this frame, ignore this one
	if (attacker->getLastCommandFrame() >= BWAPI::Broodwar->getFrameCount() || attacker->isAttackFrame())
	{
		return;
	}

	// get the unit's current command
	BWAPI::UnitCommand currentCommand(attacker->getLastCommand());

	// if we've already told this unit to attack this target, ignore this command
	if (currentCommand.getType() == BWAPI::UnitCommandTypes::Attack_Unit &&	currentCommand.getTarget() == target)
	{


		return;
	}

	// if nothing prevents it, attack the target
	attacker->attack(target);
}